home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1996 / MacHack 1996.toast / Hacks / Hacks ’95 / NetFractal™ / Fractal 8 source / NetPoint.cpp < prev    next >
Encoding:
Text File  |  1995-06-24  |  836 b   |  58 lines  |  [TEXT/MPCC]

  1. //    NetBuf.cpp
  2.  
  3. #include "NetPoint.h"
  4. #include <stdio.h>
  5.  
  6.  
  7. NetPoint::NetPoint()
  8. {
  9.     fCloseOnDestroy = false;
  10. }
  11.  
  12.  
  13. NetPoint::~NetPoint()
  14. {
  15.     if (fCloseOnDestroy)
  16.         Close();
  17. }
  18.  
  19.  
  20. OSErr
  21. NetPoint::Open(
  22.     const char *protocol)
  23. {
  24.     OSStatus err;
  25.  
  26.     fEndpoint = OTOpenEndpoint(OTCreateConfiguration(protocol), 0, NULL, &err);
  27.     if (!err) {
  28.         fCloseOnDestroy = true;
  29.     }
  30.     return err;
  31. }
  32.  
  33.  
  34. OSErr
  35. NetPoint::Bind(
  36.     short port)
  37. {
  38.     OSStatus err;
  39.     InetAddress inAddress;
  40.     TBind inBuf = { { sizeof(InetAddress), sizeof(InetAddress), (UInt8*) &inAddress }, 0 };
  41.     TBind outBuf = { { sizeof(InetAddress), sizeof(InetAddress), (UInt8*) &fMyAddress }, 0 };
  42.  
  43.     inAddress.fAddressType = AF_INET;
  44.     inAddress.fHost = 0;
  45.     inAddress.fPort = port;
  46.     err = OTBind(fEndpoint, &inBuf, &outBuf);
  47.  
  48.     return err;
  49. }
  50.  
  51.  
  52. OSErr
  53. NetPoint::Close()
  54. {
  55.     return OTCloseProvider(fEndpoint);
  56. }
  57.  
  58.